package com.metadata_system.api_server.common_server;

import com.metadata_system.api.annotations.CheckTokenUser;
import com.metadata_system.common.enums.AllConst;
import com.metadata_system.common.utils.UploadFileUtil;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.cloud.context.config.annotation.RefreshScope;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.multipart.MultipartFile;

@RestController("commonFileController")
@RequestMapping(value = "/api/common-server/v001/File/")
@Slf4j
@RefreshScope
public class FileController {

    @Autowired
    private UploadFileUtil uploadFileUtil;

    @Value("${spring.profiles.active:local}")
    private String springProfilesActive;

    @RequestMapping(value = "upload", method = {RequestMethod.GET, RequestMethod.POST})
    @CheckTokenUser
    public Object upload(
            @RequestParam(name = "myUploadFile", required = true) MultipartFile myUploadFile,
            @RequestParam(name = "fileType", required = false) String fileType
    ) {
//        if (AllConst.UploadFileTypeMap.get(fileType)==null){
//            throw new RuntimeException("上传文件类型错误："+ fileType);
//        }
        return uploadFileUtil.uploadFile(myUploadFile);
    }

}

